﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Automobile.service.UI
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //判断上一次是否记住了密码，如果上次记住了，则取出记住的密码
                HttpCookie c = Request.Cookies["login"];
                if (c != null)
                {
                    this.email.Value = c["uname"];
                    this.password.Value = c["upwd"];
                    this.j_remember.Checked = true;
                }
            }
        }

        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            //然后判断记住密码复选框是否勾选，如果勾选，则要记住密码，否则不记住【分两种情况，一种是从没有记住，一种是曾经记住过，那么本次要清除曾经记住过的】
            if (this.j_remember.Checked == true)
            {
                //通过Cookie对象，实现记住密码的功能
                HttpCookie cookie = new HttpCookie("login");  //login是键名
                cookie["uname"] = this.email.Value;   //用户名是子键名称
                cookie["upwd"] = this.password.Value;    //密码是子键名称 

                cookie.Expires = DateTime.Now.AddDays(10);  //设置当前的Cookie存储10天，有效期
                //通过Response对象把Cookie数据发送到客户端存储，或者Cookie对象的存储通过Response对象完成
                Response.Cookies.Add(cookie);
            }
        }
    }
}